package com.ly.hotel.spainterface.jg.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by ThinkPad on 2018/3/8.
 */

public class DecToHexUtils {
    private boolean isFrist = false;

    /*public String removeSpeciallyChar(String targetString,char speciallyChar){
        String decToHexString = "";
        for(int i = 0;i < targetString.length();i ++){
            if(targetString.charAt(i) != speciallyChar){
                decToHexString += targetString.charAt(i);
                if (! isFrist){
                    isFrist = true;
                }
            }else if(targetString.charAt(i) == speciallyChar && isFrist == true) {
                decToHexString += targetString.charAt(i);
            }
        }
        return decToHexString;
    }*/

    public String getDecToHex(String targetString){
        String decToHexString = replaceBlank(targetString);
        String hexNum = Integer.toHexString(Integer.parseInt(decToHexString)).toUpperCase();
        return hexNum;
    }

    public String replaceBlank(String str) {
        String dest = "";
        if (str!=null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }
}
